<#include "/admin/common/header.ftl">
<link href="/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<body class="with-padding">
<table id="dataGrid" class="table"></table>
<#include "/admin/common/footer.ftl">
<script src="/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<script>
    var dg = $('#dataGrid').bootstrapTable({
        method: "get",//请求方式
        url: "/admin/member/getMemberList",//数据源
        uniqueId: "memberId",
        dataField: "list",
        search: true,
        pagination: true,//是否分页
        clickToSelect: true,
        singleSelect: true,
        sidePagination: "server",//服务端分页
        queryParamsType: "",
        columns: [
            {
                checkbox: true
            },
            {
                title: "会员名称",
                field: "name",
                formatter: function (val, row) {
                    var name = val;
                    if (row.isAdmin) {
                        name += "<span class='new'>管理员</span>"
                    }
                    if (row.isNew) {
                        return name + "<span class='new'>new</span>";
                    } else {
                        return name;
                    }
                }
            },
            {
                title: "性别",
                field: "sexS"
            },
            {
                title: "联系电话",
                field: "mobile"
            },
            {
                title: "注册时间",
                field: "createTime"
            },
            {
                title: "积分",
                field: "memberPoints"
            },
            {
                title: "账户余额",
                field: "memberBalance",
                formatter: function (val) {
                    return val.toFixed(2);
                }
            },
            {
                title: "操作",
                field: "",
                align: "center",
                formatter: function (val, row) {
                    var a = "<button class=\"btn btn-link\" onclick=\"view(" + row.memberId + ")\" type=\"button\"><i class=\"icon " +
                            "icon-eye-open\"></i>查看详情</button>";
                    if (row.isAdmin){
                        return  a + "<button class=\"btn btn-link\" onclick=\"cancelAdmin(" + row.memberId + ")\" type=\"button\"><i class=\"icon " +
                                "icon-coffee\"></i>取消管理员</button>";
                    } else {
                        return  a + "<button class=\"btn btn-link\" onclick=\"setAdmin(" + row.memberId + ")\" type=\"button\"><i class=\"icon " +
                                "icon-user\"></i>设置管理员</button>";
                    }
                }
            }
        ]
    });

    function view(memberId) {
        location.href = "/admin/member/memberDetail?memberId=" + memberId;
    }

    function setAdmin(memberId) {
        bootbox.confirm({
            title: "操作提示",
            size: "small",
            message: "你确定要将该会员设置为管理员吗？管理员可在移动端拥有管理订单的权限，请谨慎操作！",
            callback: function (result) {
                if (result) {
                    $.ajax({
                        type: 'post',
                        url: '/admin/member/setAdmin?memberId=' + memberId,
                        success: function (data) {
                            successTip(data, dg);
                        }
                    });
                }
            }
        })
    }
    function cancelAdmin(memberId) {
        bootbox.confirm({
            title: "操作提示",
            size: "small",
            message: "你确定要将该会员取消设置管理员吗？他将会失去移动端拥有管理订单的权限，请谨慎操作！",
            callback: function (result) {
                if (result) {
                    $.ajax({
                        type: 'post',
                        url: '/admin/member/setAdmin?memberId=' + memberId,
                        success: function (data) {
                            successTip(data, dg);
                        }
                    });
                }
            }
        })
    }
</script>
</body>
</html>